package com.wxh.jdk8;

import java.util.Arrays;
import java.util.List;

/**
 * @ClassName: LambdaTest
 * @Description: lambada表达式使用
 * @Author wxh
 * @Date: 2019/8/27 16:33
 * @Version V1.0.0
 * @Since 1.8
 */
public class LambdaTest {
    public static void main(String[] args) {
        // lambda (参数列表) -> 表达式或声明语句
        new Thread(()-> System.out.println("I am running")).start();
        // jdk1.8 以前用法
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                System.out.println("hello not lambda");
            }
        };
        runnable.run();
        // jdk1.8及以后用法
        Runnable runnable2 = ()-> System.out.println("hello lambda");
        runnable2.run();

        List<String> languages = Arrays.asList("Java", "Scala", "C++", "Haskell", "Lisp");
        languages.forEach(x-> System.out.println(x));
        languages.stream().filter(x-> x.equals("Java")).forEach(x-> System.out.println(x));
    }
}
